package com.welchapps.nporganizer;

import com.welchapps.nporganizer.NotePad.NoteColumns;

import android.content.Context;
import android.database.Cursor;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CursorAdapter;
import android.widget.TextView;

public class MyCursorAdapter extends CursorAdapter {
	
	public MyCursorAdapter(Context context, Cursor c) {
		super(context, c);
	}
 
	@Override
	public void bindView(View view, Context context, Cursor cursor) {
			
		TextView color = (TextView)view.findViewById(R.id.color);
        String s = cursor.getString(
				cursor.getColumnIndex(NoteColumns.COLOR)).toLowerCase();
		TextView name = (TextView)view.findViewById(android.R.id.text1);

		name.setText(cursor.getString(
				cursor.getColumnIndex(NoteColumns.NAME)));
		TextView brand = (TextView)view.findViewById(R.id.text3);
		brand.setText(cursor.getString(
				cursor.getColumnIndex(NoteColumns.BRAND)));
			
	    if (s.contains("blue"))
	        color.setBackgroundColor(Color.parseColor("#0000FF"));
	    else if (s.contains("red"))
	        color.setBackgroundColor(Color.parseColor("#DC143C"));
	    else if (s.contains("pink"))
	        color.setBackgroundColor(Color.parseColor("#FF69B4"));
	    else if (s.contains("green"))
	        color.setBackgroundColor(Color.parseColor("#008000"));
	    else if (s.contains("white"))
	        color.setBackgroundColor(Color.parseColor("#FFFFFF"));   
	    else if (s.contains("gold"))
	        color.setBackgroundColor(Color.parseColor("#FFD700")); 
	    else if (s.contains("orange"))
	        color.setBackgroundColor(Color.parseColor("#FFA500")); 
	    else if (s.contains("purple"))
	        color.setBackgroundColor(Color.parseColor("#800080")); 
	    else if (s.contains("yellow"))
	        color.setBackgroundColor(Color.parseColor("#FFFF00")); 
	    else if (s.contains("silver"))
	        color.setBackgroundColor(Color.parseColor("#C0C0C0")); 
	    else 
	        color.setBackgroundColor(Color.parseColor("#000000"));


	}
 
	@Override
	public View newView(Context context, Cursor cursor, ViewGroup parent) {
		LayoutInflater inflater = LayoutInflater.from(context);
		View v = inflater.inflate(R.layout.noteslist_item, parent, false);
		bindView(v, context, cursor);
		return v;
	}
}
